<?php
/**
 * 分组信息
 */

namespace app\common\model\mysql;
use think\Model;
class AdminGroup extends Model
{
    protected $name = 'admin_group';

    /**
     * 根据条件查询信息
     * @param array $where
     * @param array $whereOr
     * @param array $displayField
     * @param array $hideField
     * @param array $order
     * @return Admin|array|mixed|Model|void|null
     */
    public function getFindModel(array $where=[], array $whereOr=[], array $displayField=[], array $hideField=[], array $order=[]){
        try{
            return $this->where($where)
                ->where(function ($query) use ($whereOr) { $query->whereOr($whereOr); })
                ->field($displayField)
                ->withoutField($hideField)
                ->order($order)
                ->find();
        }catch (\Exception $e){
            exception($e,'mysql.UserInfo.getFindModel');
        }
    }

    /**
     * 分页列表数据
     * @param $where
     * @param $displayField
     * @param $hideField
     * @param $order
     * @param $page
     * @param $limit
     * @return \think\Paginator|void
     */
    public function pagingListDataSql($where=[],$displayField=[],$hideField=[],$order=[],$page=1,$limit=10)
    {
        try{
            return $this->with([
                    'departmentInfo' => function($query){
                    $query->field("id,name");
                    },
                ])->where($where)
                ->field($displayField)
                ->withoutField($hideField)
                ->order($order)
                ->paginate([
                    'list_rows'=>$limit,
                    'page'=>$page
                ]);
        }catch (\Exception $e){
            exception($e,'mysql.UserInfo.getListData');
        }
    }

    /**
     * 列表数据
     * @param $where
     * @param $displayField
     * @param $hideField
     * @param $order
     * @return UserInfo[]|array|\think\Collection|void
     */
    public function listDataSql($where=[],$displayField=[],$hideField=[],$order=[])
    {
        try{
            return $this->where($where)
                ->field($displayField)
                ->withoutField($hideField)
                ->order($order)
                ->select();
        }catch (\Exception $e){
            exception($e,'mysql.UserInfo.getListData');
        }
    }

    /**
     * 更新信息
     * @param $query //更新条件
     * @return array|false|void
     */
    public function updateDataModel($query){
        try{
            if(!is_array($query)){
                return false;
            }
            return $this->update($query);
        }catch (\Exception $e){
            exception($e,'mysql.UserInfo.updateDataModel');
        }
    }


    /**
     * 修改多个值
     * @param $list
     * @return false|\think\Collection|void
     */
    public function updateMultiple($list)
    {
        try{
            if(!is_array($list)){
                return false;
            }
            return $this->saveAll($list);
        }catch (\Exception $e){
            exception($e,'mysql.UserInfo.updateMultiple');
        }
    }

    public function multiplePrimaryKeys($where){
        try{
            return $this->select($where);
        }catch (\Exception $e){
            exception($e,'mysql.UserInfo.multiplePrimaryKeys');
        }
    }

    /**
     * 根据用户条件返回信息
     * @param $where
     * @return Admin|array|mixed|Model|void|null
     */
    public function getConditionalQuery($where)
    {
        try{
            return $this->where($where)->find();
        }catch (\Exception $e){
            exception($e,'mysql.RoleMenu.getFindModel');
        }
    }

    /**
     * 根据用户条件返回多条信息
     * @param $where
     * @return Admin[]|array|\think\Collection|void
     */
    public function getConditionalQueryAll($where)
    {
        try{
            return $this->where($where)->select();
        }catch (\Exception $e){
            exception($e,'mysql.RoleMenu.getFindModel');
        }
    }
}
